mod utils;

use wasm_bindgen::prelude::*;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen(start)]
pub fn main() -> Result<(), JsValue> {
    let window = web_sys::window().expect("Oh fiddlesticks");
    let document = window.document().expect("What now?");
    let body = document.body().expect("should have");

    let val = document.create_element("p")?;
    val.set_inner_html("Greetings!");

    body.append_child(&val)?;

    Ok(())
}

#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() {
    alert("Hello, website!");
}

#[wasm_bindgen]
pub fn exponentiate(x: u32, y: u32) -> u32 {
    u32::pow(x, y)
}
